package edu.uclm.esi.tysw.tusEntradas.acciones;

import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

import edu.uclm.esi.tysw.tusEntradas.domain.Usuario;

public class Identificar extends ActionSupport {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String username;
	private String pwd;
	private Exception exception;
	
	public String execute() {
		try {
			Usuario user=new Usuario(username, this.pwd);
			ActionContext.getContext().getSession().put("user", user);
			return SUCCESS;
		} finally{}/*catch (ErrorDeAccesoException e) {
			this.exception=e;
			return ERROR;
		} catch (SQLException e) {
			this.exception=e;
			return ERROR;
		} */
	}

	public String getPwd() {
		return pwd;
	}

	public void setPwd(String pwd) {
		this.pwd = pwd;
	}

	public void setUser(String username) {
		this.username = username;
	}

	public String getUser() {
		return username;
	}
	
	public void setQuery(String query) throws ParseException {
		System.out.println(query);
		JSONParser parser=new JSONParser();
		JSONObject jUser=(JSONObject) parser.parse(query);
		this.username=(String) jUser.get("email");
		this.pwd=(String) jUser.get("pwd");
	}

	public void setException(Exception exception) {
		this.exception = exception;
	}

	public Exception getException() {
		return exception;
	}
}
